\hypertarget{class_r_t_o_s_1_1mutex}{\section{R\-T\-O\-S\-:\-:mutex Class Reference}
\label{class_r_t_o_s_1_1mutex}\index{R\-T\-O\-S\-::mutex@{R\-T\-O\-S\-::mutex}}
}


mutual execlusion semaphore  




{\ttfamily \#include $<$p\-R\-T\-O\-S.\-h$>$}

\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_r_t_o_s_1_1mutex_a018aed6b83cf182b9990ac90a3254904}{mutex} (const char $\ast$name=\char`\"{}\char`\"{})
\begin{DoxyCompactList}\small\item\em constructor, specify the name \end{DoxyCompactList}\item 
\hyperlink{class_r_t_o_s_1_1mutex_a58255b4d832c8140f2b45efcc2065733}{$\sim$mutex} (void)
\begin{DoxyCompactList}\small\item\em generates an error \end{DoxyCompactList}\item 
\hypertarget{class_r_t_o_s_1_1mutex_aef6201cdf6b86c532629b5888d740303}{void \hyperlink{class_r_t_o_s_1_1mutex_aef6201cdf6b86c532629b5888d740303}{print} (std\-::ostream \&stream, bool header=true) const }\label{class_r_t_o_s_1_1mutex_aef6201cdf6b86c532629b5888d740303}

\begin{DoxyCompactList}\small\item\em prints a mutex, for debugging only. \end{DoxyCompactList}\item 
void \hyperlink{class_r_t_o_s_1_1mutex_a52160d98a50d74a44fc4592a4625c6ed}{wait} (void)
\item 
void \hyperlink{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}{signal} (void)
\begin{DoxyCompactList}\small\item\em release the mutex \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Friends}
\begin{DoxyCompactItemize}
\item 
\hypertarget{class_r_t_o_s_1_1mutex_aa5b30b5b619f01a5d94b779bf0e58610}{class {\bfseries R\-T\-O\-S}}\label{class_r_t_o_s_1_1mutex_aa5b30b5b619f01a5d94b779bf0e58610}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
mutual execlusion semaphore 

\begin{DoxyVerb}  A mutex (mutual exclusion semaphore) is a synchronization mechanism 
  that is used to give a task exclusive access to some resource: 
  the task can execute a sequence of statements, being sure that 
  no other task is accessing the same resource. 

  A typical use is to protect a resource (for instance global data)
  that should be used by only one task at a time, so it can update
  it and leave it in a consistent state.   

  A mutex is not created for a particular task, and it is not a waitable.

  Initially a mutex is free. 
  The mutex::wait() operation blocks the task until the mutex is free, 
  and then claims the mutex for the executing task. 
  The mutex::signal() operation frees the mutex again. 
  It is an error to call mutex::signal on a mutex that is not 
  currently owned by the executing task.

  The example below shows two tasks that write messages to the 
  LCD display. Each task writes to its own line. 
  For the demonstration, after each LCD operation a sleep() 
  is put to allow the other tasks to run. 
  A mutex prevents the other task from accessing the LCD 
  while the first one is still using it. 

  @code 
\end{DoxyVerb}
 T\-B\-W  

\subsection{Constructor \& Destructor Documentation}
\hypertarget{class_r_t_o_s_1_1mutex_a018aed6b83cf182b9990ac90a3254904}{\index{R\-T\-O\-S\-::mutex@{R\-T\-O\-S\-::mutex}!mutex@{mutex}}
\index{mutex@{mutex}!RTOS::mutex@{R\-T\-O\-S\-::mutex}}
\subsubsection[{mutex}]{\setlength{\rightskip}{0pt plus 5cm}R\-T\-O\-S\-::mutex\-::mutex (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name = {\ttfamily \char`\"{}\char`\"{}}}
\end{DoxyParamCaption}
)}}\label{class_r_t_o_s_1_1mutex_a018aed6b83cf182b9990ac90a3254904}


constructor, specify the name 

The name is used for debugging only. \hypertarget{class_r_t_o_s_1_1mutex_a58255b4d832c8140f2b45efcc2065733}{\index{R\-T\-O\-S\-::mutex@{R\-T\-O\-S\-::mutex}!$\sim$mutex@{$\sim$mutex}}
\index{$\sim$mutex@{$\sim$mutex}!RTOS::mutex@{R\-T\-O\-S\-::mutex}}
\subsubsection[{$\sim$mutex}]{\setlength{\rightskip}{0pt plus 5cm}R\-T\-O\-S\-::mutex\-::$\sim$mutex (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}\label{class_r_t_o_s_1_1mutex_a58255b4d832c8140f2b45efcc2065733}


generates an error 

A mutex should never be destroyed 

\subsection{Member Function Documentation}
\hypertarget{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}{\index{R\-T\-O\-S\-::mutex@{R\-T\-O\-S\-::mutex}!signal@{signal}}
\index{signal@{signal}!RTOS::mutex@{R\-T\-O\-S\-::mutex}}
\subsubsection[{signal}]{\setlength{\rightskip}{0pt plus 5cm}void R\-T\-O\-S\-::mutex\-::signal (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}\label{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}


release the mutex 

If one or more tasks are waiting for the mutex the firs one is released, and it now owns the mutex. Otherwise, if the mutex is cleared it is now set.

It is an error for a task to call \hyperlink{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}{signal()} on a mutex that it does not own (that it did not call \hyperlink{class_r_t_o_s_1_1mutex_a52160d98a50d74a44fc4592a4625c6ed}{wait()} on). After the signal the task no longer owns the mutex. \hypertarget{class_r_t_o_s_1_1mutex_a52160d98a50d74a44fc4592a4625c6ed}{\index{R\-T\-O\-S\-::mutex@{R\-T\-O\-S\-::mutex}!wait@{wait}}
\index{wait@{wait}!RTOS::mutex@{R\-T\-O\-S\-::mutex}}
\subsubsection[{wait}]{\setlength{\rightskip}{0pt plus 5cm}void R\-T\-O\-S\-::mutex\-::wait (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}\label{class_r_t_o_s_1_1mutex_a52160d98a50d74a44fc4592a4625c6ed}
claim the mutex

If the mutex was set it it is now cleared, and the calling task owns the mutex.

Otherwise the current task waits (is halted) until the owning task calls \hyperlink{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}{signal()} on the same mutex. The \hyperlink{class_r_t_o_s_1_1mutex_a9a6cb88e182f977bce35e024449b24cd}{signal()} calls will release the tasks in the order of their \hyperlink{class_r_t_o_s_1_1mutex_a52160d98a50d74a44fc4592a4625c6ed}{wait()} calls. 

The documentation for this class was generated from the following files\-:\begin{DoxyCompactItemize}
\item 
p\-R\-T\-O\-S.\-h\item 
p\-R\-T\-O\-S.\-cpp\end{DoxyCompactItemize}
